"""
Brier分数 = mean((y_pred_prop - y_true)^2)
"""
import numpy as np
from sklearn.metrics import brier_score_loss


def get_data():
    """

    :return:
    """
    y_true = [0, 0, 1, 1]
    y_pred = [0, 0.5, 0.3, 0.9]
    return y_true, y_pred


def compute_brier(y_true, y_pred):
    """
    :param y_true:
    :param y_pred: 预测概率
    :return:
    """
    return np.power(np.array(y_pred) - np.array(y_true), 2).mean()


def run():
    """
    主程序
    :return:
    """
    y_true, y_pred = get_data()

    # 自己计算
    my_brier = compute_brier(y_true=y_true, y_pred=y_pred)

    brier_scores = brier_score_loss(y_true=y_true, y_prob=y_pred)

    info = 'brier_score: my: {}, sklearn: {}'.format(my_brier, brier_scores)
    print(info)


if __name__ == '__main__':
    run()
